package com.tedu.weibo.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration //该注解让当前类作为SpringBoot的配置类，可以在上面自定义配置信息(其它配置信息的前提是该类必须是配置即必须先有@Configuration注解)，SpringBoot在启动时会采用这些配置来初始化并启动
@MapperScan("com.tedu.weibo.mapper") //()括号里为包路径 该注解用于告知mybatis启动时扫描哪个包(包括子孙包，这个包(包括子孙包)里的所有类必须都是mapper 好处：1.不再单给类加@Mapper注解 2.mybatis不再扫描所有包去找mapper包)
@EnableSwagger2WebMvc // 允许
public class Config {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tedu.weibo.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("微博项目")
                .description("微博项目在线API文档")
                .version("1.0")
                .contact(new Contact("那山","www.doc.codeboy.com","18888888888"))
                .build();
    }

}
